package k_shardingJDBC;

import io.shardingjdbc.core.api.algorithm.sharding.PreciseShardingValue;
import io.shardingjdbc.core.api.algorithm.sharding.standard.PreciseShardingAlgorithm;

import java.util.Collection;

/**
 * 实现  数据库表 算法
 * @author Y
 *
 */
public final class ModuloShardingTableAlgorithm implements PreciseShardingAlgorithm<Long>{

	@Override
	public String doSharding(final Collection<String> tableNames,
			final PreciseShardingValue<Long> shardingValue) {
		for (String each : tableNames) {
			if (each.endsWith(shardingValue.getValue() % 2 +"")) {
				return each;
			}
		}
		throw new UnsupportedOperationException();
	}

}
